package com.listener;

import com.api.service.v1.HeartAPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Service;

@Service
public class RedisMessageListener implements MessageListener {

    @Autowired
    private HeartAPIService heartService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        String expireKey = new String(message.getBody());
        String[] arry = expireKey.split("_");
        if (arry!=null && arry.length>1)
        {
            String key = arry[0];
            String value = arry[1];
            switch (key)
            {

                case "heart":
                    String mac = value;
                    heartService.offLine(mac);
                    break;
                case "miyaoKey":
                    String sj = value;
                    heartService.PasswordKey(sj);
                    break;
            }
        }


    }
}